package com.itheima.utils;

import org.apache.commons.lang.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {

    public static String dateToString(Date date){
        if (date != null){
            String dateString = new SimpleDateFormat("yyy-MM-dd").format(date);
            return dateString;
        }else {
            return null;
        }
    }

    public static Date stringToDate(String dateString) throws ParseException {
        if (StringUtils.isNotEmpty(dateString)){
            return new SimpleDateFormat("yyy-MM-dd").parse(dateString);
        }else {
            return null;
        }
    }
}